﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections;

/// <summary>
///Good 的摘要说明
/// </summary>
public class GoodOfCart
{
    public GoodOfCart()
    {
        //
        //TODO: 在此处添加构造函数逻辑
        //
    }

    private int _ID;                            //商品ID
    private string _GoodNo;                     //产品编号
    private int _BrindID;                       //产品品牌ID
    private string _GoodTypeID;                 //产品类别ID
    private string _GoodName_CN;                //中文名字
    private string _GoodName_EN;                //英文名字  
    private double _Price_Orig;                 //原价
    private double _Price_Lastin;               //进贷价
    private double _Price_Vip;                  //会员价
    private double _Price_BV;                   //BV值
    private string _Good_Unit;                  //产品计量单位
    private string _Introduction;               //产品介绍
    private string _Introduction_Details;       //产品详细介绍
    private string _FilePic_Small;              //产品小图
    private string _FilePic_Big;                //产品大图
    private string _GoodNorm;                   //产品规格
    private string _GoodColor;                  //产品颜色
    private int _Amount;                        //数量
    private double _SumMoney;                   //金额
    private double _Weight;                     //重量
    public int ID
    {
        get { return _ID; }
        set { _ID = value; }
    }

    public string GoodNo
    {
        get { return _GoodNo; }
        set { _GoodNo = value; }
    }

    public int BrindID
    {
        get { return _BrindID; }
        set { _BrindID = value; }
    }

    public string GoodTypeID
    {
        get { return _GoodTypeID; }
        set { _GoodTypeID = value; }
    }

    public string GoodName_CN
    {
        get { return _GoodName_CN; }
        set { _GoodName_CN = value; }
    }

    public string GoodName_EN
    {
        get { return _GoodName_EN; }
        set { _GoodName_EN = value; }
    }

    public double Price_Orig
    {
        get { return _Price_Orig; }
        set { _Price_Orig = value; }
    }

    public double Price_Lastin
    {
        get { return _Price_Lastin; }
        set { _Price_Lastin = value; }
    }

    public double Price_Vip
    {
        get { return _Price_Vip; }
        set { _Price_Vip = value; }
    }

    public double Price_BV
    {
        get { return _Price_BV; }
        set { _Price_BV = value; }
    }
    public double Weight
    {
        get { return _Weight; }
        set { _Weight = value; }
    }
    public string Good_Unit
    {
        get { return _Good_Unit; }
        set { _Good_Unit = value; }
    }

    public string Introduction
    {
        get { return _Introduction; }
        set { _Introduction = value; }
    }

    public string Introduction_Details
    {
        get { return _Introduction_Details; }
        set { _Introduction_Details = value; }
    }

    public string FilePic_Small
    {
        get { return _FilePic_Small; }
        set { _FilePic_Small = value; }
    }

    public string FilePic_Big
    {
        get { return _FilePic_Big; }
        set { _FilePic_Big = value; }
    }

    public string GoodNorm
    {
        get { return _GoodNorm; }
        set { _GoodNorm = value; }
    }

    public string GoodColor
    {
        get { return _GoodColor; }
        set { _GoodColor = value; }
    }

    public int Amount
    {
        get { return _Amount; }
        set { _Amount = value; }
    }

    public double SumMoney
    {
        get { return _SumMoney; }
        set { this._SumMoney = value; }
    }

    /// <summary>
    /// 加载购物车
    /// </summary>
    public static ArrayList GetItems(string filename, ref string Sum)
    {
        HttpCookie c = HttpContext.Current.Request.Cookies[filename];
        double totalMoney = 0;

        ArrayList items = new ArrayList();
        if (c != null && c.HasKeys)
        {
            for (int i = 0; i < c.Values.Count; i++)
            {
                string[] vals = c.Values[i].Split('|');

                GoodOfCart Good = new GoodOfCart();
                Good.ID = int.Parse(vals[0]);
                Good.Amount = int.Parse(vals[1]);
                Good.GoodNorm = Microsoft.JScript.GlobalObject.unescape(vals[2].ToString());
                Good.GoodColor = Microsoft.JScript.GlobalObject.unescape(vals[3].ToString());

                DataTable dt = new DAL.Tables.tbl_Shop_Good().Open("", "ID=" + Good.ID.ToString(), "");
                if (dt != null && dt.Rows.Count > 0)
                {
                    DataRow dr = dt.Rows[0];
                    Good.GoodNo = dr["GoodNo"].ToString();
                    Good.FilePic_Small = dr["GoodPic_Small"].ToString();
                    Good.GoodName_CN = dr["GoodName_CN"].ToString();
                    Good.Price_Orig = double.Parse(dr["Price_Orig"].ToString());
                    Good.Price_Vip = double.Parse(dr["Price_Vip"].ToString());
                    //Good.GoodNorm = dr["GoodNorm"].ToString();
                    //Good.GoodColor = dr["GoodColor"].ToString();

                    Good.SumMoney = Good.Amount * Good.Price_Vip;

                    totalMoney = totalMoney + Good.SumMoney;
                }

                items.Add(Good);
            }

            Sum = totalMoney.ToString();
        }

        return items;
    }

    /// <summary>
    /// 加载新式购物车
    /// </summary>
    public static ArrayList GetNewItems(string filename, ref string GoodWeight, ref string GoodPrice_Orig, ref string GoodPrice_Vip, ref string Sum)
    {
        HttpCookie c = HttpContext.Current.Request.Cookies[filename];
        double GoodWeihgts = 0;
        double GoodPrice_Origs = 0;
        double GoodPrice_Vips = 0;
        double totalMoney = 0;

        ArrayList items = new ArrayList();
        if (c != null && c.HasKeys)
        {
            for (int i = 0; i < c.Values.Count; i++)
            {
                string[] vals = c.Values[i].Split('|');

                GoodOfCart Good = new GoodOfCart();
                Good.ID = int.Parse(vals[0]);
                Good.Amount = int.Parse(vals[1]);
                Good.GoodNorm = Microsoft.JScript.GlobalObject.unescape(vals[2].ToString());
                Good.GoodColor = Microsoft.JScript.GlobalObject.unescape(vals[3].ToString());

                DataTable dt = new DAL.Tables.tbl_Shop_Good().Open("", "ID=" + Good.ID.ToString(), "");
                if (dt != null && dt.Rows.Count > 0)
                {
                    DataRow dr = dt.Rows[0];
                    Good.GoodNo = dr["GoodNo"].ToString();
                    Good.FilePic_Small = dr["GoodPic_Small"].ToString();
                    Good.GoodName_CN = dr["GoodName_CN"].ToString();
                    Good.Price_Orig = double.Parse(dr["Price_Orig"].ToString());
                    Good.Price_Vip = double.Parse(dr["Price_Vip"].ToString());
                    //Good.GoodNorm = dr["GoodNorm"].ToString();
                    //Good.GoodColor = dr["GoodColor"].ToString();
                    Good.Weight = double.Parse(dr["Weight"].ToString());
                    Good.SumMoney = Good.Amount * Good.Price_Vip;

                    GoodWeihgts += Good.Weight;
                    GoodPrice_Origs += Good.Price_Orig * Good.Amount;
                    GoodPrice_Vips += Good.Price_Vip * Good.Amount;
                    totalMoney += Good.SumMoney;
                }

                items.Add(Good);
            }
            GoodWeight = GoodWeihgts.ToString();
            GoodPrice_Orig = GoodPrice_Origs.ToString();
            GoodPrice_Vip = GoodPrice_Vips.ToString();
            Sum = totalMoney.ToString();
        }

        return items;
    }

    /// <summary>
    /// 加载浏览历史
    /// </summary>
    public static ArrayList GetItemsByHistory(string filename, ref string Sum)
    {
        HttpCookie c = HttpContext.Current.Request.Cookies[filename];
        double totalMoney = 0;

        ArrayList items = new ArrayList();
        if (c != null && c.HasKeys)
        {
            for (int i = (c.Values.Count - 1); i >= 0; i--)
            {
                string[] vals = c.Values[i].Split('|');

                GoodOfCart Good = new GoodOfCart();
                Good.ID = int.Parse(vals[0]);
                Good.Amount = int.Parse(vals[1]);
                Good.GoodNorm = Microsoft.JScript.GlobalObject.unescape(vals[2].ToString());
                Good.GoodColor = Microsoft.JScript.GlobalObject.unescape(vals[3].ToString());

                DataTable dt = new DAL.Tables.tbl_Shop_Good().Open("", "ID=" + Good.ID.ToString(), "");
                if (dt != null && dt.Rows.Count > 0)
                {
                    DataRow dr = dt.Rows[0];
                    Good.GoodNo = dr["GoodNo"].ToString();
                    Good.FilePic_Small = dr["GoodPic_Small"].ToString();
                    Good.GoodName_CN = dr["GoodName_CN"].ToString();
                    Good.Price_Orig = double.Parse(dr["Price_Orig"].ToString());
                    Good.Price_Vip = double.Parse(dr["Price_Vip"].ToString());
                    //Good.GoodNorm = dr["GoodNorm"].ToString();
                    //Good.GoodColor = dr["GoodColor"].ToString();

                    Good.SumMoney = Good.Amount * Good.Price_Vip;

                    totalMoney = totalMoney + Good.SumMoney;
                }

                items.Add(Good);
            }

            Sum = totalMoney.ToString();
        }

        return items;
    }
}
